package lego.jbv;

import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;
import lejos.util.Delay;

public class BumperControl extends Thread{
	private TouchSensor left;
	private TouchSensor right;
	private BumperStatus status;

	public BumperControl(SensorPort leftTouch, SensorPort rightTouch)
	{
		left = new TouchSensor(leftTouch);
		right = new TouchSensor(rightTouch);
		
		status = new BumperStatus();
		
		this.setDaemon(true);
		this.setName("BumperControl");
	}
	
	public synchronized BumperStatus getStatus() {
		return status;
	}

	public synchronized void setStatus(BumperStatus status) {
		this.status = status;
	}
	
	@Override
	public void run()
	{
		while(true)
		{
			if(left.isPressed() && right.isPressed())
			{
				status.setObjectInCenter();
			}
			
			else if(left.isPressed() && !right.isPressed())
			{
				status.setObjectToLeft();
			}
			
			else if(!left.isPressed() && right.isPressed())
			{
				status.setObjectToRight();
			}
			
			else
			{
				status.noObjects();
			}
			
			Delay.msDelay(200);
		}
	}
}
